package business.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import model.Transport;
import model.Trunk;
import model.VTransportLine;
import business.basic.iHibBaseDAO;
import business.basic.iHibBaseDAOImpl;
import business.dao.TransportDAO;

@Component("transportdao")
public class TransportDAOImpl implements TransportDAO {

	private iHibBaseDAO bdao = null;
	
	public TransportDAOImpl(){
		bdao = new iHibBaseDAOImpl();
	}
	
	public void setBdao(iHibBaseDAO bdao){
		this.bdao = bdao;
	}
	
	@Override
	public int add(Transport transport) {
		Object obj = bdao.insert(transport);
		if(obj!=null){
			return Integer.parseInt(obj.toString());
		}
		return 0;
	}

	@Override
	public boolean update(Transport transport) {
		return bdao.update(transport);
	}

	@Override
	public boolean delete(int transportid) {
		return bdao.delete(Transport.class,transportid);
	}

	@Override
	public Transport getTransportId(int transportid) {
		return (Transport)bdao.findById(Transport.class,transportid);
	}

	@Override
	public List<VTransportLine> getTransport() {
		String hql = "from VTransportLine";
		return bdao.select(hql);
	}

	@Override
	public List<VTransportLine> getTransportByWhere(String wherecondition,
			int startPage, int pageSize) {
		String hql = "from VTransportLine";
		if(wherecondition!=null && !wherecondition.equals("")){
			hql += wherecondition;
		}
		return bdao.selectByPage(hql, startPage, pageSize);
	}

	@Override
	public int getAmounTransportByWhere(String wherecondition) {
		String hql = "select count(*) from VTransportLine ";
		if (wherecondition != null && !wherecondition.equals("")) {
			hql += wherecondition;
		}
		return bdao.selectValue(hql);
	}

}
